package com.woniuxy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.MaintainRecordMapper;
import com.woniuxy.pojo.MaintainRecord;
import com.woniuxy.service.MaintainRecordService;
import com.woniuxy.util.DataGridView;
import com.woniuxy.vo.MaintainRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MaintainRecordImpl implements MaintainRecordService {
    @Autowired
    private MaintainRecordMapper maintainRecordMapper;

    @Override
    public DataGridView selectMaintainRecordsByProperty(MaintainRecordVo maintainRecordVo) {
        Page<Object> page = PageHelper.startPage(maintainRecordVo.getPage(), maintainRecordVo.getLimit());
        List<MaintainRecord> maintainRecords = maintainRecordMapper.selectMaintainRecordsByProperty(maintainRecordVo);
        return new DataGridView(page.getTotal(), maintainRecords);
    }

    @Transactional
    @Override
    public void deleteMaintainRecordById(int id) {
        maintainRecordMapper.deleteMaintainRecordById(id);
    }

    @Transactional
    @Override
    public void removeMaintainRecord(Integer[] ids) {
        if (ids != null && ids.length > 0) {
            for (Integer id : ids) {
                this.deleteMaintainRecordById(id);
            }
        }
    }
    @Transactional
    @Override
    public boolean insertMaintainRecord(MaintainRecord maintainRecord) {
        boolean flag=false;
        int i = maintainRecordMapper.insertMaintainRecord(maintainRecord);
        if (i>0){
            flag=true;
        }
        return flag;
    }
    @Transactional
    @Override
    public boolean updataMaintainRecord(MaintainRecord maintainRecord) {
        boolean flag=false;
        int i = maintainRecordMapper.updataMaintainRecord(maintainRecord);
        if (i>0){
            flag=true;
        }
        return flag;
    }
}
